package timeManager;

/**
 * 
 * @author Ganggao Zhu
 * 
 * This class is used to count the run time in different time format.
 *
 */

public class TimeManager {

	Long start;
	Long end;
	Long elapsed;

	public static final Long SECOND = new Long(1000);
	public static final Long MINUTE = new Long(60 * 1000);
	public static final Long HOUR = new Long(60 * 60 * 1000);
	public static final Long DAY = new Long(24 * 60 * 60 * 1000);

	TimeManager() {
		start = new Long(0);
		end = new Long(0);
		elapsed = new Long(0);
	}

	public Long getStart() {
		return start;
	}

	public void setStart(Long start) {
		this.start = start;
	}

	public Long getEnd() {
		return end;
	}

	public void setEnd(Long end) {
		this.end = end;
	}

	public Long getElapsed() {
		return elapsed;
	}

	public void setElapsed(Long elapsed) {
		this.elapsed = elapsed;
	}


	public int getElapsedSec() {
		if (elapsed > SECOND)
			return (int) (elapsed / SECOND);
		else
			return 0;
	}

	public int getElapsedMin() {
		if (elapsed > MINUTE)
			return (int) (elapsed / MINUTE);
		else
			return 0;
	}

	public int getElapsedHour() {
		if (elapsed > HOUR)
			return (int) (elapsed / HOUR);
		else
			return 0;
	}

	public int getElapsedDay() {
		if (elapsed > DAY)
			return (int) (elapsed / DAY);
		else
			return 0;
	}
	
	public Long getElapsedTime(){
		return getEnd() - getStart();
	}
	
	public void setStartTime(){
		setStart(System.currentTimeMillis());
	}
	
	public void setEndTime(){
		setEnd(System.currentTimeMillis());
	}
	
	public void startTimer(Long timer){
		setElapsed(timer);
		setStartTime();
	}
	
	public boolean isTimerEnd(){
		setEndTime();
		if(getElapsedTime() > getElapsed())
			return true;
		else return false;
	}

}
